package com.share.service.attach.advertise.impl;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.share.bean.attach.advertise.PositionItem;
import com.share.dao.attach.advertise.PositionItemDao;
import com.share.service.attach.advertise.PositionItemManager;

@Service
public class PositionItemManagerImpl implements PositionItemManager {

	@Resource
	private PositionItemDao pitemDao ;
	
	public void setPitemDao(PositionItemDao pitemDao) {
		this.pitemDao = pitemDao;
	}

	@Override
	public void deletePositionItemManager(int id) throws Exception {
		this.pitemDao.deletePositionItemDao(id) ;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PositionItem> findAllPositionItemManager(int pid)
			throws Exception {
		
		String hql = "select o from PositionItem o" ;
		
		StringBuffer whereHQL = new StringBuffer() ;
		whereHQL.append("ps_id=?") ;
		
		List param = new ArrayList() ;
		param.add(pid) ;
		
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>() ;
		orderby.put("id", "asc") ;
		
		return this.pitemDao.findAllPositionItemDao(hql, whereHQL.toString(), param, orderby) ;
	}

	@Override
	public PositionItem loadByIdPositionItemManager(int id)
			throws Exception {
		
		return this.pitemDao.loadByIdPositionItemDao(id) ;
	}

	@Override
	public void savePositionItemManager(PositionItem pi)
			throws Exception {
		this.pitemDao.savePositionItemDao(pi) ;

	}

	@Override
	public void updatePositionItemManager(PositionItem pi)
			throws Exception {
		this.pitemDao.updatePositionItemDao(pi) ;
	}

}
